package com.seventeen.controller.portal;

import com.seventeen.common.Const;
import com.seventeen.common.ResponseCode;
import com.seventeen.common.ServerResponse;
import com.seventeen.pojo.User;
import com.seventeen.service.ICartService;
import com.seventeen.vo.CartVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("cart")
public class CartController {

    private ICartService iCartService;

    //购物车List列表
    @RequestMapping("list")
    public ServerResponse cartList(HttpSession session){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if (user == null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录，请登录");
        }

        //查询数据库购物车数据
        return null;
    }


    //加入购物车
    @RequestMapping("add")
    @ResponseBody
    public ServerResponse<CartVo> add(HttpSession session, Integer count, Integer produceId){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if(user == null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登陆，请先登陆");
        }
        return iCartService.add(user.getId(),produceId,count);
    }
}
